/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pt.iasd.youthshelter.honor.nodes;

import java.awt.event.ActionEvent;
import java.util.ResourceBundle;
import javax.swing.AbstractAction;
import javax.swing.Action;
import static javax.swing.Action.NAME;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.windows.TopComponent;
import pt.iasd.youthshelter.datamodel.Honor;
import pt.iasd.youthshelter.honor.HonorEditorTopComponent;

/**
 *
 * @author Rui
 */
public class HonorNode extends AbstractNode {
    private static final ResourceBundle bundle = java.util.ResourceBundle.getBundle("pt/iasd/youthshelter/honor/Bundle");
    
    private Honor honor;
    
    public HonorNode(Honor honor) {
        super(Children.LEAF);
        this.honor = honor;
        setDisplayName(this.honor.getName());
    }

    @Override
    public Action getPreferredAction() {
        return new OpenHonorAction();
    }

    @Override
    public Action[] getActions(boolean context) {
        return new Action[]{new OpenHonorAction()};
    }
    
    private class OpenHonorAction extends AbstractAction {
        public OpenHonorAction() {
            putValue(NAME, bundle.getString("Action.Open"));
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            TopComponent editor = new HonorEditorTopComponent(honor);
            editor.open();
            editor.requestActive();
        }
    }
}
